<?php
class Search{
	function Search(){
		include("search.methodTable.php");
		include("database.php");
	}
	function searchAll($search){
		$output->user = $this->searchStudent($search);
		$output->project = $this->searchProject($search);
		return $output;
	}
	function searchStudent($search){
		$WHERE = " WHERE ";
		$counter = 0;
		$keywords = array();
        $keywords = explode(" ",$search);
		foreach($keywords as $key=>$word)
        {
			if ($counter > 0) { $WHERE .= " OR "; }
			$counter++; 
			$WHERE .= " firstname LIKE '%{$word}%'  OR lastname LIKE '%{$word}%' OR city LIKE '%{$word}%' ";
		}

		$sql = "SELECT * FROM user $WHERE";
		$query = mysql_query($sql);
		return $query;
	}
	function searchProject($search){
		$WHERE = " WHERE ";
		$counter = 0;
		$keywords = array();
        $keywords = explode(" ",$search);
		foreach($keywords as $key=>$word)
        {
			if ($counter > 0) { $WHERE .= " OR "; }
			$counter++; 
			$WHERE .= " title LIKE '%{$word}%'  OR description LIKE '%{$word}%' ";
		}

		$sql = "SELECT * FROM project $WHERE";
		$query = mysql_query($sql);
		return $query;
	}
}	
?>